package leetcode.D200.T167;

class Solution {
    // 一刷
    /*public int[] twoSum(int[] numbers, int target) {
        int left = 0, right = numbers.length-1;
        while(left < right) {
            int sum = numbers[left] + numbers[right];
            if(sum == target) {
                return new int[]{left+1, right+1};
            } else if(sum < target) {
                left++;
            } else {
                right--;
            }
        }
        return new int[]{left, right};
    }*/

    // 二刷
    public int[] twoSum(int[] numbers, int target) {
        int i = 0, j = numbers.length-1;
        while (i < j) {
            int sum = numbers[i] + numbers[j];
            if (sum == target) {
                return new int[] {i+1, j+1};
            } else if (sum < target) {
                ++i;
            } else {
                --j;
            }
        }
        return new int[] {i, j};
    }
}